using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class SLOCMap : EntityTypeConfiguration<SLOC>
    {
        public SLOCMap()
        {
            // Primary Key
            this.HasKey(t => new { t.UTYPEID, t.LOCID });

            // Properties
            this.Property(t => t.LOCID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("SLOC");
            this.Property(t => t.UTYPEID).HasColumnName("UTYPEID");
            this.Property(t => t.LOCID).HasColumnName("LOCID");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasRequired(t => t.Location)
                .WithMany(t => t.SLOCs)
                .HasForeignKey(d => d.LOCID);
            this.HasRequired(t => t.UserType)
                .WithMany(t => t.SLOCs)
                .HasForeignKey(d => d.UTYPEID);

        }
    }
}
